url = 'https://www.acwing.com/problem/content/844/'


def dfs(u):
    if u == n:
        for d in res_list:
            print(d, end=' ')
        print()

    for i in range(n):
        if not res_opt[i]:
            res_list[u] = i + 1
            res_opt[i] = True
            dfs(u + 1)
            res_opt[i] = False


if __name__ == '__main__':
    n = int(input())

    res_list = [0] * n
    res_opt = [False] * n

    dfs(0)
